<template>
  <view class="u-flex-1">
    <u-input v-model="value" :placeholder="placeholder" type="select" :border="false" @click="show = true"
      :select-open="show" :input-align="inputAlign" />
    <u-picker v-model="show" mode="time" :params="params" @confirm="pickerConfirm">
    </u-picker>
  </view>
</template>

<script>
export default {
  name: "yer-date-second",
  props: {
    defaultValue: "", //默认显示的字典，传字典的代码项
    defaultValueExtra: "", //默认显示的字典，传字典的代码项
    inputAlign: {
      type: String,
      default: "left",
    }, //input内容对齐方式三种：left  center  right  默认left
    placeholder: {
      type: String,
      default: "请选择",
    },
    showModel: {
      type: Number,
      default: 0,
    }, //日期显示格式 可选1对应yyyy-MM-dd HH:mm:ss和2对应yyyy-MM-dd HH:mm 3对应HH:mm 默认yyyy-MM-dd
  },
  emits: ["update:modelValue", "input"],
  data() {
    return {
      showValue: "",
      value: "", //字典展示的值，对应的是字典名称
      show: false, //控制select弹框的显示
      params: {
        year: true,
        month: true,
        day: true,
        hour: true,
        minute: true,
        second: true,
      },
    };
  },
  methods: {
    clear() {
      this.showValue = "";
      this.value = "";
    },
    pickerConfirm(e) {
      let res = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`;
      this.value = res;
      this.$emit("update:modelValue", res);
      this.$emit("input", res);
    },
  },
  watch: {
    value: function (newVal, oldVal) {
      this.$emit("update:modelValue", newVal);
      this.$emit("input", newVal);
    },
    defaultValue: {
      immediate: true,
      handler: function (newVal, oldVal) {
        // console.log('newVal',newVal);
        if (newVal) {
          this.value = newVal;
        }
      },
    }
  }
};
</script>

<style></style>
